@extends('layouts.header')
@section('title','添加')
@section('content')
    <article class="page-container">
        <form class="form form-horizontal" id="form-cityCode-add" autocomplete="off">
            <div class="row cl">
                <label class="form-label col-sm-3"><span class="c-red">*</span>城市：</label>
                <div class="formControls col-sm-9">
                    <input type="text" class="input-text" value="" placeholder="" id="name" name="name" autofocus="autofocus">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-sm-3"><span class="c-red">*</span>编码：</label>
                <div class="formControls col-sm-9">
                    <input type="text" class="input-text" value="" placeholder="" id="code" name="code" autofocus="autofocus">
                </div>
            </div>

            @csrf

            <div class="row cl pt-20">
                <div class="col-sm-9 col-sm-offset-3">
                    <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                    <input class="btn btn-danger radius ml-15" type="button" value="&nbsp;&nbsp;关闭&nbsp;&nbsp;"
                           onclick="layer_close();">
                </div>
            </div>
        </form>
    </article>
    <script type="text/javascript">
        $(function () {
            var index2;

            $('.skin-minimal input').iCheck({
                checkboxClass: 'icheckbox-blue',
                radioClass: 'iradio-blue',
                increaseArea: '20%'
            });


            $("#form-cityCode-add").validate({
                rules: {
                    name: {
                        required: true,
                        notSpace: true,
                    },
                    code: {
                        required: true,
                        notSpace: true,
                    },
                },
                // onkeyup:false,
                // focusCleanup:false,
                success: "valid",
                submitHandler: function (form) {
                    $(form).ajaxSubmit({
                        type: 'post',
                        url: "", //自己提交给自己可以不写url   
                        //beforeSend  beforeSubmit

                        beforeSend: function () {
                            //0.4透明度 白色遮罩
                            index2 = layer.load(2, {
                                shade: [0.3, '#fff']
                            });
                        },
                        complete: function () {
                            layer.close(index2);
                        },
                        success: function (data) {
                            //判断添加结果 
                            if (data === '1') {
                                // window.location.href = '/{{ config('constant.name_admin') }}/volCode/add?id=' + select2Val.val();//刷新
                                parent.table_reload(0); //0停留在当前页，1回到第一页
                                parent.layer.msg('添加成功!', {
                                    icon: 1,
                                    time: 2000
                                });
                                var index = parent.layer.getFrameIndex(window.name);

                                parent.layer.close(index);
                            } else {
                                layer.msg('添加失败!', {
                                    icon: 2,
                                    time: 2000
                                });
                            }
                        },
                        error: function (data) {
                            ajax_error(data);
                        }
                    });
                }
            });
        });
    </script>
@endsection